package com.woniuxy.controller;

import com.woniuxy.annotations.RequirePerm;
import com.woniuxy.entity.utils.ResponseEntity;
import com.woniuxy.service.OrderService;
import com.woniuxy.service.OrderServiceByProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@RefreshScope   // 热部署
public class OrderController {
    // 热刷新测试
    @Value("${woniu.config}")
    private String myConfig;
    @Value("${server.port}")
    int port;
    @Autowired
    OrderService orderService;
    @Autowired
    OrderServiceByProduct orderServiceByProduct;

    @PostMapping("/{pid}/{num}")
    @RequirePerm(perms = {"order::add", "order::edit"})
    public ResponseEntity generateOrder(@PathVariable Integer pid, @PathVariable Integer num) {
        ResponseEntity generateOrder = orderService.generateOrder(pid, num);
//        generateOrder.put("port", port);
        return generateOrder;
    }

    @GetMapping("/{name}/{minPrice}/{maxPrice}")
    public ResponseEntity findProductList(@PathVariable String name, @PathVariable double minPrice, @PathVariable double maxPrice) {
        return orderServiceByProduct.findProductList(name, minPrice, maxPrice);
    }

    @GetMapping("/showConfig")
    public ResponseEntity showConfig(){
        return new ResponseEntity(myConfig);
    }
}
